import NavConfig from "@/utils/nav.config.json";
import { Docs } from "./interfaces";

let docs: Docs[] = [];

const addComponent = (arr: Docs[]) => {
  const indexArr: number[] = [];
  arr.forEach((elem, i) => {
    const { items } = elem;
    if (items) {
      addComponent(items);
      docs = [...docs, ...items];
      indexArr.push(i);
      docs.splice(indexArr[0], 1);
    } else {
      elem.component = () => import(`../docs/${elem.name}.md`);
    }
  });
};
Object.keys(NavConfig).forEach((elem) => {
  docs = [...docs, ...(NavConfig as any)[elem]];
});

addComponent(docs);

const exportDocs = docs;

export default exportDocs;
